<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="模版名字" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入模版名字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模版范围" prop="scope">
        <el-select v-model="queryParams.scope" placeholder="请选择模版范围" clearable size="small">
          <el-option
            v-for="dict in scopeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索模板</el-button>
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dms:drug_model:add']"
        >新增模板</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

    </el-row>

    <el-table v-loading="loading" :data="drug_modelList">
      <el-table-column label="模版编号" align="center" prop="id" />
      <el-table-column label="模版名字" align="center" prop="name" />
      <el-table-column label="模版范围" align="center" prop="scope" :formatter="scopeFormat" />
      <el-table-column label="模版简介" align="center" prop="aim" />
      <el-table-column label="模版编码" align="center" prop="code" />
      <el-table-column label="模板类型" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dms:drug_model:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dms:drug_model:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listDrug_model, delDrug_model, } from "@/api/dms/drug_model";

export default {
  name: "Drug_model",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 药品模版管理表格数据
      drug_modelList: [],
      // 弹出层标题
      // title: "",
      // 是否显示弹出层
      open: false,
      // 模版范围字典
      scopeOptions: [],
      // 模板类型字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        scope: null,
      },
      // 表单参数
      // form: {},
      // 表单校验
      // rules: {
      // }
    };
  },
  created() {
    this.getList();
    this.getDicts("dms_model_scoe").then(response => {
      this.scopeOptions = response.data;
    });
    this.getDicts("dms_model_typeId").then(response => {
      this.typeOptions = response.data;
    });
  },
  methods: {
    /** 查询药品模版管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.type=1;
      listDrug_model(this.queryParams).then(response => {
        this.drug_modelList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 模版范围字典翻译
    scopeFormat(row, column) {
      return this.selectDictLabel(this.scopeOptions, row.scope);
    },
    // 模板类型字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    /** 搜索按钮操作 */
    handleQuery() {

      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.push({path:"/model/edit_drug_model"});
      // 销毁组件，避免通过vue-router再次进入时，仍是上次的history缓存的状态
      this.$destroy(true);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.push({path:"/model/edit_drug_model",query:{id:id}});
      // 销毁组件，避免通过vue-router再次进入时，仍是上次的history缓存的状态
      this.$destroy(true);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      const type = row.type
      this.$confirm('是否确认删除药品模版管理编号为"' + row.name + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDrug_model(ids,type);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
  }
};
</script>
